package com.cupk.rotaryguard.monitor.controller;

import com.cupk.common.base.utils.result.Result;
import com.cupk.rotaryguard.monitor.service.MonitorRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tjy
 * @date 2023/4/1
 * @apiNote
 */
@RestController
@RequestMapping("/monitor/record")
public class MonitorRecordController {

    @Resource
    private MonitorRecordService monitorRecordService;

    /**
     * 查询所有监控记录
     *
     * @return
     */
    @GetMapping("/list-all")
    public Result getMonitorRecords() {
        return monitorRecordService.getMonitorRecords();
    }

    /**
     * 根据id获取record
     *
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public Result getMonitorRecordById(
            @PathVariable Long id) {
        return monitorRecordService.getMonitorRecordById(id);
    }

    /**
     * 根据设备id获取监控记录(记录时间倒序)
     *
     * @param pageNum
     * @param pageSize
     * @param deviceId
     * @return
     */
    @GetMapping("/info-device-id")
    public Result getMonitorRecordByDeviceId(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestParam(defaultValue = "") Long deviceId) {
        return monitorRecordService.getMonitorRecordByDeviceId(pageNum, pageSize, deviceId);
    }

    /**
     * 根据设备id获取最新一条监控记录
     *
     * @param deviceId
     * @return
     */
    @GetMapping("/info-device-id-latest/{deviceId}")
    public Result getLatestMonitorRecordByDeviceId(@PathVariable Long deviceId) {
        return monitorRecordService.getLatestMonitorRecordByDeviceId(deviceId);
    }

    /**
     * 删除监控记录
     *
     * @param ids
     * @return
     */
    @PostMapping("/del")
    public Result delMonitorRecords(@RequestBody List<Integer> ids) {
        return monitorRecordService.delMonitorRecords(ids);
    }

    /**
     * 删除监控记录
     *
     * @param id
     * @return
     */
    @PostMapping("/del/{id}")
    public Result delMonitorRecordById(@PathVariable Integer id) {
        return monitorRecordService.delMonitorRecordById(id);
    }

    /**
     * 获取指定设备最新50条数据用于诊断
     *
     * @param id
     * @return
     */
    @GetMapping("/get/last-fifty-records/{id}")
    public Result lastFiftyRecords(@PathVariable Long id) {
        return monitorRecordService.lastFiftyRecords(id);
    }

    /**
     * 获取指定设备最新10条数据用于展示
     *
     * @param deviceId
     * @return
     */
    @GetMapping("/get/last-ten-records/{deviceId}")
    public Result getTenRecordByDeviceId(@PathVariable Long deviceId) {
        return monitorRecordService.getTenRecordByDeviceId(deviceId);
    }
}
